package cn.net.shuxing.yifu.common.service;

import cn.net.shuxing.yifu.common.bean.ContentFreshman;
import cn.net.shuxing.yifu.common.bean.ContentNews;
import cn.net.shuxing.yifu.common.bean.ContentSys;
import cn.net.shuxing.yifu.common.constant.OssConstant;
import cn.net.shuxing.yifu.common.dto.DateTimeVo;
import cn.net.shuxing.yifu.common.mapper.ContentFreshmanMapper;
import cn.net.shuxing.yifu.common.util.CommonExample;
import cn.net.shuxing.yifu.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class ContentFreshmanService extends ContentService<ContentFreshman, ContentFreshmanMapper> {

    @Autowired
    private OssCommonService ossCommonService;

    @Override
    protected void complete(ContentFreshman bean) {
        if (bean == null)
            return;
        LocalDateTime createTime = bean.getCreateTime();
        DateTimeVo dateTimeVo = new DateTimeVo(createTime);
        bean.setDateTimeVo(dateTimeVo);

        if (StringUtils.hasText(bean.getFreshmanDetail())) {
            bean.setFreshmanLinkUrl(ossCommonService.getUrl(OssConstant.ossBucketName, bean.getFreshmanDetail()));
        }
    }

    public ContentFreshman getByInlienLink(String link) {
        CommonExample example = new CommonExample(ContentSys.class);
        example.equals("freshmanLink", link);
        return getByExampleWithoutComplete(example);
    }
}
